
<!--
  Preview this file by prepending http://htmlpreview.github.io/? to its URL
  e.g. http://htmlpreview.github.io/?https://raw.githubusercontent.com/Azure/bicep/main/src/monarch/test/baselines/issue4152.html
-->
<html>
  <head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/styles/default.min.css">
  </head>
  <body>
    <pre class="hljs">
<span class="hljs-keyword">var</span> <span class="hljs-variable">elements</span> = [
  {
    <span class="hljs-variable">id</span>: <span class="hljs-string">&#39;</span><span class="hljs-string">abc&#39;</span>
    <span class="hljs-variable">name</span>: <span class="hljs-string">&#39;</span><span class="hljs-string">foo&#39;</span>
  }
  {
    <span class="hljs-variable">id</span>: <span class="hljs-string">&#39;</span><span class="hljs-string">def&#39;</span>
    <span class="hljs-variable">name</span>: <span class="hljs-string">&#39;</span><span class="hljs-string">bar&#39;</span>
  }
]

<span class="hljs-comment">// equivalent to the above proposed: createObject(elements, x =&gt; x.id)</span>
<span class="hljs-keyword">var</span> <span class="hljs-variable">keyedById</span> = <span class="hljs-variable">reduce</span>(<span class="hljs-variable">elements</span>, {}, (<span class="hljs-variable">prev</span>, <span class="hljs-variable">cur</span>) =&gt; <span class="hljs-variable">union</span>(<span class="hljs-variable">prev</span>, { <span class="hljs-string">&#39;</span>${<span class="hljs-variable">cur</span>.<span class="hljs-variable">id</span>}<span class="hljs-string">&#39;</span>: <span class="hljs-variable">cur</span> }))

<span class="hljs-comment">// equivalent to the above proposed: createObject(elements, x =&gt; x.id, x =&gt; x.name)</span>
<span class="hljs-keyword">var</span> <span class="hljs-variable">nameById</span> = <span class="hljs-variable">reduce</span>(<span class="hljs-variable">elements</span>, {}, (<span class="hljs-variable">prev</span>, <span class="hljs-variable">cur</span>) =&gt; <span class="hljs-variable">union</span>(<span class="hljs-variable">prev</span>, { <span class="hljs-string">&#39;</span>${<span class="hljs-variable">cur</span>.<span class="hljs-variable">id</span>}<span class="hljs-string">&#39;</span>: <span class="hljs-variable">cur</span>.<span class="hljs-variable">name</span> }))


    </pre>
  </body>
</html>